export interface IMap<K, V> {
  hasKey(key: K): boolean;
  set?(key: K, value: V): boolean;
  put?(key: K, value: V): boolean;
  hasCode?(key: K): number;
  remove(key: K): boolean;
  get(key: K): V | undefined;
  keyValues(): ValuePair<K, V>[];
  keys(): K[];
  values(): V[];
  forEach(callbackFn: (key: K, value: V) => any): void;
  size(): number;
  isEmpty(): boolean;
  clear(): void;
  toStr(): string;
}

/** 成对辅助类
 *
 */
export class ValuePair<K, V> {
  constructor(public key: K, public value: V) {}
  toStr() {
    return `[#${this.key}:${this.value}]`;
  }
}

/** 默认的字符串转换函数: 用于将其他类型的数据转换为字符串
 *
 * @param item
 * @returns
 */
export function defaultToString(item: any): string {
  if (item === null) {
    return "null";
  } else if (item === undefined) {
    return "undefined";
  } else if (typeof item === "string" || item instanceof String) {
    return `${item}`;
  }
  return item.toString();
}
